package cn.dmrliu.edu.realtime.util;

import cn.dmrliu.edu.realtime.common.EduConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.sql.Connection;

public class RedisUtil {

    public static JedisPool jedisPool;

    static {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMinIdle(5);
        jedisPoolConfig.setMinIdle(5);
        jedisPoolConfig.setMaxTotal(100);
        jedisPoolConfig.setMaxWaitMillis(2000);
        jedisPoolConfig.setBlockWhenExhausted(true);
        jedisPoolConfig.setTestOnBorrow(true);
        jedisPool = new JedisPool(jedisPoolConfig, "h102", 6379, 10000, EduConfig.REDIS_PASSWORD);

    }

    public static Jedis getConnection() {
        Jedis resource = jedisPool.getResource();
        return resource;
    }
}
